package servlets.admin;

import java.io.IOException;
import java.util.List;
import java.util.UUID;

import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import entities.User;

import managers.EntityFunctionManager;

/**
 * Servlet implementation class ListUsers.
 * Lorsque on veut afficher les utilisateurs, on appelle cet 
 * servlet.
 */
public class ListUsers extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ListUsers() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
    @EJB EntityFunctionManager mng;
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		List<User> list = mng.listUsersNonValide();
		
		//for(int i=0; i<list.size(); i++)
			//System.out.println(list.get(i).getClass());
		String goTo="ListNewUsers.jsp";
		String myObjectId = UUID.randomUUID().toString();	
		request.getSession().setAttribute(myObjectId, list);
		request.setAttribute("data", list);
		//System.out.print(request.getSession().getAttribute(myObjectId));
		request.getRequestDispatcher(goTo).forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request,response);
	}

}
